$(function () {
    console.log('dom准备好了')

    $('#btnQuery').click(function () {
        let keyword = $('[name=keyword]').val();
        let obj = {
            keyword
        };
        $.post('/Home/Query', obj, function (res) {
            console.log(res)
            let tb = $('#tb');
            let tbtr = $('.tbtr');
            tbtr.html("");
            res.forEach(item => {
                let html = `
                <tr class="tbtr">
                    <td>${item.id}</td>
                    <td>${item.studnetName}</td>
                    <td>${item.remarks}</td>
                    <td>
                        <input type="button" onclick="btnEdit(${item.id})" value="编辑">
                        <input type="button" onclick="btnDel(${item.id})" value="删除">
                    </td>
                </tr>
                `
                tb.append(html);
            });
        })
    })
    $('#btnAdd').click(function () {
        window.location.href = '/Home/CreateOrEdit'

    })
    $('#btnSave').click(function () {
        let Id = $('[name=id]').val();
        let StudentName = $('[name=StudentName]').val();
        let Remarks = $('[name=Remarks]').val();
        let obj = {
            Id, StudentName, Remarks
        }
        $.post('/Home/Save', obj, function () {
            alert("保存好了")
            window.location.href='/Home/Index'
        })
    })
    $('#btnCencel').click(function () {
        window.location.href = '/Home/Index'
    })
})
function btnEdit(id) {
    window.location.href = `/Home/CreateOrEdit/${id}`

}
function btnDel(id) {
    if (confirm("确定要删除吗")) {
        window.location.href = `/Home/Delete/${id}`
    }
}